package server;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import constants.Constants;

public class Client {

	private int id = Constants.NO_CLIENT_ID;
	private int universeId=Constants.NO_UNIVERSE_ID;
	private Socket socket=null;
	private DataInputStream flujoEntrada=null; 
	private DataOutputStream flujoSalida=null;
	
	public Client (){
		id = Constants.NO_CLIENT_ID;
		socket=null;
	}
	
	
	public Client(Socket skCliente) throws IOException {
		this.socket=skCliente;
		InputStream aux = socket.getInputStream();
		//genera el flujo de entrada, por aca RECIBO los mensajes que vienen de este cliente
		flujoEntrada = new DataInputStream( aux );
		OutputStream aux1 = socket.getOutputStream();
		flujoSalida =  new DataOutputStream(aux1);
	}


	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public Socket getSocket() {
		return socket;
	}
	public void setSocket(Socket socket) throws IOException {
		this.socket = socket;
		InputStream aux = socket.getInputStream();
		//genera el flujo de entrada, por aca RECIBO los mensajes que vienen de este cliente
		flujoEntrada = new DataInputStream( aux );
		OutputStream aux1 = socket.getOutputStream();
		flujoSalida =  new DataOutputStream(aux1);
	}
	public DataInputStream getFlujoEntrada() {
		return flujoEntrada;
	}
	public void setFlujoEntrada(DataInputStream flujoEntrada) {
		this.flujoEntrada = flujoEntrada;
	}
	public DataOutputStream getFlujoSalida() {
		return flujoSalida;
	}
	public void setFlujoSalida(DataOutputStream flujoSalida) {
		this.flujoSalida = flujoSalida;
	}


	public String read() throws IOException {
		
		return flujoEntrada.readUTF().toString();
	}


	public void write(String message) throws IOException {
		if(socket==null){
			return;
		}
		flujoSalida.writeUTF(message);
		
	}


	public int getUniverseId() {
		return universeId;
	}


	public void setUniverseId(int universeId) {
		this.universeId = universeId;
	}
	
	
	
	
}
